package com.ebt.m.wiki;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.IView;

/**
 * Created by wanglu on 2017/10/18.
 */

public class ProductSearchHistoryTag extends IView {
    TextView timeLabel;
    ImageButton delete;
    View divider;

    public ProductSearchHistoryTag(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        inflate(context, R.layout.layout_product_history_title, this);
        timeLabel = (TextView) findViewById(R.id.tx_time);
        delete = findViewById(R.id.delete);
        divider = findViewById(R.id.divider);
    }

    public ProductSearchHistoryTag(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ProductSearchHistoryTag(Context context) {
        this(context, null);
    }

    @Override
    public void update(Object... args) {
        String tag = (String) args[0];
        boolean showDivider = (boolean) args[1];
        timeLabel.setText(tag);
        if (showDivider) {
            divider.setVisibility(View.VISIBLE);
        } else {
            divider.setVisibility(View.GONE);
        }

        if (tag.contains("记录")) {
            delete.setVisibility(View.VISIBLE);
            delete.setOnClickListener(view -> {
                if (mOnclickListner != null) {
                    mOnclickListner.onClick(view);
                }
            });
        } else {
            delete.setVisibility(View.GONE);
        }

    }
}
